<template>
  <div>login</div>
</template>

<script setup lang="ts">
  import { onMounted, reactive, ref, computed } from 'vue';
  import useStore from '@/store/index';
  import { useRouter, useRoute } from 'vue-router';

  const router = useRouter();
  const route = useRoute();
  const store = useStore();
  // data

  //mounted

  // computed

  // methods
  onMounted(() => {
    // 取路由传递的参数 params的同理
    const { query } = route;
    console.log(query);
  });
  const toIndex = () => {
    router.push('/index');
  };

  console.log('login中使用vuex辅助函数：mapGetters');
  console.log(store.getName);

  store.setName('login中使用vuex辅助函数：mapMutations');

  interface IRes {
    code: number;
    data: object | null;
    message: string | null;
  }
  const onLoing = (res: IRes) => {
    if (res && res.data) {
      const data = res.data;
      console.log(data);
      // 登录后先重置之前添加的路由，避免重复
      // resetRouter();

      // 设置用户登录信息
      // auth.setToken(data.accessToken);
      // auth.setUserInfo(data);
      // this.$store.commit("SETUSERINFO", data);
      // 用接口返回的菜单对比定义好的路由表，筛选出可以访问的路由

      // 默认跳转实时监控页面。除非带有redirect参数
      // const toPath = decodeURIComponent(this.$route.query.redirect || "/monitor/monitorManage");
      // this.$router.replace(toPath);
    }
  };
</script>

<style></style>
